from django.db import models


class Publish(models.Model):
    nid = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    add = models.CharField(max_length=32)
    email = models.EmailField()


class Book(models.Model):
    nid = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    # 阅读数
    reat_num = models.IntegerField(default=0)
    # 评论数
    commit_num = models.IntegerField(default=0)
    pub_date = models.DateField()
    price = models.DecimalField(max_digits=5, decimal_places=2)
    publish = models.ForeignKey(to='Publish', to_field='nid', on_delete=models.CASCADE)
    authors = models.ManyToManyField(to='Author')




class Author(models.Model):
    nid = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    authorDetail = models.OneToOneField(to='AuthorDetail', to_field='nid', unique=True, on_delete=models.CASCADE)


class AuthorDetail(models.Model):
    nid = models.AutoField(primary_key=True)
    phone = models.BigIntegerField()
    addr = models.CharField(max_length=32)


# # 多对多
# class Book2Author(models.Model):
#     nid = models.AutoField(primary_key=True)
#     author_id=models.ForeignKey(to='Author',to_field='nid')
#     book_id=models.ForeignKey(to='Book',to_field='nid')





